﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class UserController : BaseController
    {
        protected Users GetUserInfo()
        {
            try
            {
                var auth = HttpContext.AuthenticateAsync();
                var userName = auth.Result.Principal.Claims.First(a => a.Type.Equals(ClaimTypes.Name))?.Value;
                if (string.IsNullOrEmpty(userName))
                    return null;
                var user = _users.GetModel(userName);
                var sysConfig = Common.XMLConfig.Sysconfig.loadConfig(_env.ContentRootPath);
                user.avatar = sysConfig.weburl + user.avatar;
                return user;
            }
            catch (Exception)
            {
                return null;
            }
            
        }
    }
}